home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-09 | 5.6 KB | 192 lines | [TEXT/MPS ] |
- {**********************************************************************************
- UValidText.p
- Classes implementing the ability to enter strings which must be validated,
- such as dates, times, numbers, and so on.
- **********************************************************************************}
-
- UNIT UValidText;
-
- INTERFACE
- USES
- { • MacApp }
- UMacApp,
- UMacAppUtilities,
-
- { • building blocks }
- UTEView,
- UDialog,
-
- { • Implementation use }
- ToolUtils; { for GetIndString() }
-
- CONST
- kValidTextErrorStrings = 700; { string list ('STR#') resource ID }
- kEmptyStringErrorStr = 1; { "You must enter a valid value…" }
-
- kEmptyStringError = -1; { error number }
-
- mTextValidated = 1100; { actual argument for itsChoice in DoChoice
- when text validates sucessfully }
-
-
-
- {###############################################################################
- Global Routines
- ###############################################################################}
-
- PROCEDURE InitUValidText;
-
-
- TYPE
- {###############################################################################
- TValidText
- TValidText is an abstract class — that is, it is never going to be
- instantiated directly. It is used to factor out the common behaviour of
- all subclasses of TEditText for which validation is non-trivial.
- ###############################################################################}
-
- ValidTextTemplatePtr = ^ValidTextTemplate;
- ValidTextTemplate = RECORD
- strict: BOOLEAN;
- required: BOOLEAN;
- alertID: INTEGER;
- END; { ValidTextTemplate }
-
- TValidText = OBJECT(TEditText)
- fStrict: BOOLEAN;
- fRequired: BOOLEAN;
- fAlertID: INTEGER;
-
- PROCEDURE TValidText.IValidText(
- itsSuperView: TView;
- itsLocation: VPoint;
- itsSize: VPoint;
- strict: BOOLEAN;
- required: BOOLEAN;
- alertID: INTEGER);
-
- PROCEDURE TValidText.IRes(
- itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr);
- OVERRIDE;
-
- PROCEDURE TValidText.WRes(
- theResource: ViewRsrcHndl;
- VAR itsParams: Ptr);
- OVERRIDE;
-
- PROCEDURE TValidText.WriteRes(
- theResource: ViewRsrcHndl;
- VAR itsParams: Ptr);
- OVERRIDE;
-
- PROCEDURE TValidText.SetStrict(
- strict: BOOLEAN);
- { Set fStrict to the given state. Note that the current text
- is always valid, and so it need not be updated to reflect this
- change. }
-
- PROCEDURE TValidText.SetRequired(
- required: BOOLEAN);
- { Sets fRequired to the given state. If TRUE, then an empty string
- will be considered to be invalid. }
-
- FUNCTION TValidText.GetStrict
- :BOOLEAN;
-
- FUNCTION TValidText.GetRequired
- :BOOLEAN;
-
- PROCEDURE TValidText.UpdateText(
- redraw: BOOLEAN);
- { This routine replaces the text in the object with text that
- reflects the object's current values. }
-
- FUNCTION TValidText.IsValid(
- VAR theText: Str255;
- VAR whyNot: INTEGER)
- :BOOLEAN;
- { If the text is valid, then this function returns TRUE, and whyNot
- is set to the value noErr (0). If the text is invalid, then the
- function returns FALSE and whyNot is set to a value indicating
- the reason why the text is invalid. }
-
- FUNCTION TValidText.HandleValidText(
- VAR theText: Str255)
- :LONGINT;
- { This routine always returns kValidValue. In its OVERRIDES, it
- might update SELF's internal instance variables to reflect
- the valid text. }
-
- FUNCTION TValidText.HandleInvalidText(
- VAR theText: Str255;
- theError: INTEGER)
- :LONGINT;
- { This routine calls either HandleAlertAccepted() or
- HandleAlertCancelled(), depending on the result returned by a
- call to ValidationErrorAlert(). }
-
- FUNCTION TValidText.HandleAlertAccepted(
- VAR theText: Str255;
- theError: INTEGER)
- :LONGINT;
- { This routine always returns kErrorHandled. Its overrides might
- do something different. }
-
- FUNCTION TValidText.HandleAlertCancelled(
- VAR theText: Str255;
- theError: INTEGER)
- :LONGINT;
- { This routine always returns kErrorHandled. Its overrides might
- do something different. }
-
- PROCEDURE TValidText.ErrorToString(
- theError: INTEGER;
- VAR theString: Str255);
- { This routine sets theString to the string which best explains
- the given error. It is intended to be called only from
- ValidationErrorAlert(), below. }
-
- PROCEDURE TValidText.PrepareErrorAlert(
- VAR theText: Str255;
- theError: INTEGER);
- { The routine sets up the dialog that is displayed by
- ValidationErrorAlert(), below. }
-
- FUNCTION TValidText.ValidationErrorAlert(
- VAR theText: Str255;
- theError: INTEGER)
- : BOOLEAN;
- { This routine displays the standard MacApp validation error alert.
- The function result (true by default) indicates whether or not
- the alert was accepted (true) or cancelled (false). }
-
- FUNCTION TValidText.Validate
- :LONGINT;
- OVERRIDE;
- { This routine returns one of the following values:
- kValidValue: the text is valid
-
- kInvalidValue: the text is invalid, and a default error alert
- should be displayed by MacApp
-
- kErrorHandled: the text is invalid, but the class handled the
- error, so MacApp doesn't have to
- }
-
- {$IFC qInspector}
- PROCEDURE TValidText.Fields(
- PROCEDURE DoToField(
- fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
- {$ENDC qInspector}
- END; { TValidText }
-
- IMPLEMENTATION
-
- {$I UValidText.inc1.p}
-
- END. { UValidText.p }